package com.logos.musicframe.service.impl;

import com.logos.musicframe.entity.PlaylistCollectCount;
import com.logos.musicframe.mapper.PlaylistCollectCountMapper;
import com.logos.musicframe.service.PlaylistCollectCountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

/**
 * 歌单收藏个数表(PlaylistCollectCount)表服务实现类
 *
 * @author logos
 * @since 2025-06-19 14:15:25
 */
@Service("playlistCollectCountService")
public class PlaylistCollectCountServiceImpl implements PlaylistCollectCountService {
    @Autowired
    private PlaylistCollectCountMapper playlistCollectCountMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PlaylistCollectCount queryById(Long id) {
        return this.playlistCollectCountMapper.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param playlistCollectCount 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<PlaylistCollectCount> queryByPage(PlaylistCollectCount playlistCollectCount, PageRequest pageRequest) {
        long total = this.playlistCollectCountMapper.count(playlistCollectCount);
        return new PageImpl<>(this.playlistCollectCountMapper.queryAllByLimit(playlistCollectCount, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param playlistCollectCount 实例对象
     * @return 实例对象
     */
    @Override
    public PlaylistCollectCount insert(PlaylistCollectCount playlistCollectCount) {
        this.playlistCollectCountMapper.insert(playlistCollectCount);
        return playlistCollectCount;
    }

    /**
     * 修改数据
     *
     * @param playlistCollectCount 实例对象
     * @return 实例对象
     */
    @Override
    public PlaylistCollectCount update(PlaylistCollectCount playlistCollectCount) {
        this.playlistCollectCountMapper.update(playlistCollectCount);
        return this.queryById(playlistCollectCount.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.playlistCollectCountMapper.deleteById(id) > 0;
    }
}
